package com.example.administrator.myproject.login

import android.Manifest
import android.annotation.TargetApi
import android.app.Activity
import android.content.ContentUris
import android.content.Intent
import android.content.pm.PackageManager
import android.database.Cursor
import android.graphics.Bitmap
import android.graphics.BitmapFactory
import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.provider.DocumentsContract
import android.provider.MediaStore
import android.support.v4.app.ActivityCompat
import android.support.v4.content.ContextCompat
import android.support.v4.content.FileProvider
import android.support.v7.app.AppCompatActivity
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.EditText
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.PopupWindow
import android.widget.TextView
import android.widget.Toast


import java.io.BufferedOutputStream
import java.io.File
import java.io.FileNotFoundException
import java.io.FileOutputStream
import java.io.IOException
import java.text.SimpleDateFormat
import java.util.Date

import cn.bmob.v3.exception.BmobException
import cn.bmob.v3.listener.SaveListener
import com.example.administrator.myproject.R
import com.example.administrator.myproject.bean.User
import java.lang.Long

class Register22 : AppCompatActivity(), View.OnClickListener {
    private var userid: EditText? = null
    private var password: EditText? = null
    private var comfirmpassword: EditText? = null
    private var address: EditText? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.register)
        userid = findViewById(R.id.et_user_account)
        password = findViewById(R.id.et_user_password)
        comfirmpassword = findViewById(R.id.et_comfrim_user_password)
        address = findViewById(R.id.et_address)
        findViewById<View>(R.id.btn_register).setOnClickListener(this)

    }

    override fun onClick(view: View) {
        when (view.id) {
            R.id.btn_register -> {
                val UserId = userid!!.text.toString()
                val Password = password!!.text.toString()
                val comfrimPassword = comfirmpassword!!.text.toString()
                val Address = address!!.text.toString()
                if (UserId.isEmpty() || Password.isEmpty() || comfrimPassword.isEmpty() || Address.isEmpty()) {
                    Toast.makeText(this, " 请填写完整的注册信息", Toast.LENGTH_SHORT).show()
                } else if (Password != comfrimPassword) {
                    Toast.makeText(this, " 请保证两次密码输入相同", Toast.LENGTH_SHORT).show()
                } else {
                    // if (file == null) {
                    //    Toast.makeText(this, "请添加图片", Toast.LENGTH_SHORT).show()
                    //} else {
                    val user = User()
                    user.userid = UserId
                    user.password = Password
                    user.address = Address
                    user.status = "1"
                    user.money = 1925
                    //  bobmBean.file = file!!.toString()
                    user.save(object : SaveListener<String>() {
                        override fun done(s: String, e: BmobException?) {
                            if (e == null) {
                                Toast.makeText(this@Register22, "发布成功", Toast.LENGTH_SHORT).show()
                                finish()
                            } else {
                                Toast.makeText(this@Register22, "发布失败", Toast.LENGTH_SHORT).show()
                            }
                        }
                    })
                    //  }
                }
            }
        }
    }
}